package com.lin.boot.aop;

import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/** * @author linjiang
 * @date 2024/5/8
 * @fn
 */
//@Configuration
public class AopConfig {

    @Bean
    public AspectJExpressionPointcut buildAspectJExpressionPointcut() {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression("execution(public * com.lin.aop.controller..*.*(..))");
        return pointcut;
    }

    @Bean
    public DefaultPointcutAdvisor buildDefaultPointcutAdvisor(
            AspectJExpressionPointcut buildAspectJExpressionPointcut,
            CustomMethodInterceptor customMethodInterceptor
    ) {
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
        advisor.setPointcut(buildAspectJExpressionPointcut);
        advisor.setAdvice(customMethodInterceptor); // 设置通知
        advisor.setOrder(3);
        return advisor;
    }
}
